import Vue from 'vue'
import axios from 'axios'

/**
 * 环境配置 store
 */
export default {
  // 开发环境下的配置信息,由于 chrome 插件的环境与浏览器不同, 不能使用process对象,所以将开发环境的变量配置在此处
  state: {
    isDev: true,
    urlOrderRoot: '/food/',
    urlOrder: '/food/order.do',
    urlOrderBumen: '/food/getBuMen.do',
    urlTimesLogin: '/times/login/validate',
    urlTimesDetailList: '/times/times/timesdetaillist',
    urlPojectType: '/times/ProjectInfo/qryprojectleaderbytype',
    urlProjectLeader: '/times/ProjectInfo/qryprojectleader',
    urlTimesAdd: '/times/times/adddetail',
    urlTimesDelete: '/times/times/deltimesdetail',
    urlTimesChange: '/times/times/chgtimedetail',
    urlTimeSubmit: '/times/times/submittimesfirst',
    urlVersion: '/inspur/version.json'
  },

  getters: {
    isDev (state) {
      return state.isDev
    },
    urlOrderRoot (state) {
      return state.urlOrderRoot
    },
    urlOrder (state) {
      return state.urlOrder
    },
    urlOrderBumen (state) {
      return state.urlOrderBumen
    },
    urlTimesLogin (state) {
      return state.urlTimesLogin
    },
    urlTimesDetailList (state) {
      return state.urlTimesDetailList
    },
    urlPojectType (state) {
      return state.urlPojectType
    },
    urlProjectLeader (state) {
      return state.urlProjectLeader
    },
    urlTimesAdd (state) {
      return state.urlTimesAdd
    },
    urlTimesDelete (state) {
      return state.urlTimesDelete
    },
    urlTimesChange (state) {
      return state.urlTimesChange
    },
    urlTimeSubmit (state) {
      return state.urlTimeSubmit
    },
    urlVersion (state) {
      return state.urlVersion
    }
  },

  mutations: {
    loadConfig (state) {
      try{
        if (process.env.NODE_ENV === 'development') {
          console.log('判定为开发环境')

          //http请求全局配置
          axios.defaults.timeout = 5 * 1000
          return
        }
      }catch(e){}

      console.log('判定为生产环境')

      //生产环境配置
      Object.assign(state,{
        isDev: false,
        urlOrderRoot: 'http://10.180.201.253:8080/food/',
        urlOrder: 'http://10.180.201.253:8080/food/order.do',
        urlOrderBumen: 'http://10.180.201.253:8080/food/getBuMen.do',
        urlTimesLogin: 'http://10.7.13.26:9080/times/login/validate',
        urlTimesDetailList: 'http://10.7.13.26:9080/times/times/timesdetaillist',
        urlPojectType: 'http://10.7.13.26:9080/times/ProjectInfo/qryprojectleaderbytype',
        urlProjectLeader: 'http://10.7.13.26:9080/times/ProjectInfo/qryprojectleader',
        urlTimesAdd: 'http://10.7.13.26:9080/times/times/adddetail',
        urlTimesDelete: 'http://10.7.13.26:9080/times/times/deltimesdetail',
        urlTimesChange: 'http://10.7.13.26:9080/times/times/chgtimedetail',
        urlTimeSubmit: 'http://10.7.13.26:9080/times/times/submittimesfirst',
        urlVersion: 'http://115.28.109.228/inspur/version.json'
      })

      //http请求全局配置
      axios.defaults.timeout = 10 * 1000
    }
  }
}